package com.myraceengineer;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;


public class DiagramActivity extends Activity {
	
	private GraphicalView mChart;


	private String[] mMonth = new String[] {
	          "Jan", "Feb" , "Mar", "Apr", "May", "Jun", "Jul", "Aug" 
	};
	
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.diagram_layout);
	    openChart();
   	}

	private void openChart()
	{
		 // Define the number of elements you want in the chart.
	     int z[]={0,1,2,3,4,5,6,7};
	     
	     
	     int x[]={10,18,32,21,48,60,53,80};
	     

	      // Create XY Series for X Series.
	      XYSeries xSeries=new XYSeries("X Series");
	     

	      //  Adding data to the X Series.
	     for(int i=0;i<z.length;i++)
	     {
	    	 xSeries.add(z[i],x[i]);	   
	     }

	        // Create a Dataset to hold the XSeries.
	     
	     XYMultipleSeriesDataset dataset=new XYMultipleSeriesDataset();
	     
	     // Add X series to the Dataset.   
	     dataset.addSeries(xSeries);
	     
	     
	     // Create XYSeriesRenderer to customize XSeries

	     XYSeriesRenderer Xrenderer=new XYSeriesRenderer();
	     Xrenderer.setColor(Color.GREEN);
	     Xrenderer.setPointStyle(PointStyle.DIAMOND);
	     Xrenderer.setDisplayChartValues(true);
	     Xrenderer.setLineWidth(2);
	     Xrenderer.setFillPoints(true);
	     
	     // Create XYMultipleSeriesRenderer to customize the whole chart

	     XYMultipleSeriesRenderer mRenderer=new XYMultipleSeriesRenderer();
	     
	     mRenderer.setChartTitle("X Vs Y Chart");
	     mRenderer.setXTitle("X Values");
	     mRenderer.setYTitle("Y Values");
	     mRenderer.setZoomButtonsVisible(true);
	     mRenderer.setXLabels(0);
	     mRenderer.setPanEnabled(false);
	   
	     mRenderer.setShowGrid(true);
	 
	     mRenderer.setClickEnabled(true);
	     
	     for(int i=0;i<z.length;i++)
	     {
	      mRenderer.addXTextLabel(i, mMonth[i]);
	     }
	     
	       // Adding the XSeriesRenderer to the MultipleRenderer. 
	     mRenderer.addSeriesRenderer(Xrenderer);
	     
	     LinearLayout chart_container=(LinearLayout)findViewById(R.id.Chart_layout);

	     // Creating an intent to plot line chart using dataset and multipleRenderer
	       
	     mChart = ChartFactory.getLineChartView(getBaseContext(), dataset, mRenderer);
	     
	     // Add the graphical view mChart object into the Linear layout .
	     chart_container.addView(mChart);
	}
	



	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.map, menu);
		
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
